<?php

/**
 * @filename IndexAction.class.php 
 * @encoding UTF-8 
 * @author nemo.xiaolan <a href="mailto:335454250@qq.com">335454250@qq.com</a>
 * @link <a href="http://www.sep-v.com">http://www.sep-v.com</a>
 * @license http://www.sep-v.com/code-license
 * @datetime 2013-11-11  15:33:54
 * @Description
 * 
 */
class IndexAction extends CommonAction {
    
    public function index() {
        $this->makeNav();
        $this->display();
    }
    
    /**
     * 根据AuthRule生成左侧导航，不同用户生成不同缓存
     * @todo 三级分类（快捷导航）
     */
    private function makeNav() {
        $navs = F("Nav/".$this->user["id"]);
        if($navs) {
            $this->assign("LeftNavs", $navs);
            return;
        }
        
        $navs = require ENTRY_PATH.DS."Conf".DS."navs.php";
        
        $auth=new Auth();
        foreach($navs as $label => $n) {
            $childs = array();
            foreach($n["childs"] as $cl => $c) {
                list($group, $module, $action) = explode("/", $c);
                $action = $action ? $action : "index";
                $authName = sprintf("%s.%s.%s", $group, $module, $action);
                
                if(!$auth->check($authName, $_SESSION["user"]["id"])) {
                    continue;
                }
                if(substr($c, 0, 1) == "#" or substr($c, 0, 11) == "javascript:") {
                    $url = $c;
                } else {
                    $url = U("/".$c);
                }
                $childs[] = array(
                    "label" => L($cl),
                    "url"   => $url
                );
            }
            
            if(substr($n["action"], 0, 1) == "#" or substr($n["action"], 0, 11) == "javascript:") {
                $url = $n["action"];
            } else {
                $url = U("/".$n["action"]);
            }
            if($childs or isset($n["action"])) {
                $theNav[] = array(
                    "childs" => $childs,
                    "label"  => L($label),
                    "icon"   => $n["icon"],
                    "url"    => $url
                );
            }
            
        }
        $navs = F("Nav/".$this->user["id"], $theNav);
//        print_r($theNav);exit;
        $this->assign("LeftNavs", $theNav);
    }
    
}

?>
